package com.ktjiaoyu.config;

import com.ktjiaoyu.cond.ConditionOnPropertyEnable;
import com.ktjiaoyu.entity.SysRole;
import com.ktjiaoyu.entity.SysUser;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;

//定义配置类
@Configuration

//指定读取外部配置文件,value指定路径,encoding指定读取时的字符编码
@PropertySource(value="classpath:user.properties",encoding = "UTF-8")

public class JavaConfig {
    //使用@value注解可以读取配置文件中的指定值
    @Value("${user.realName}")
    private String realName;
    @Value("${user.account}")
    private String account;
    @Value("${user.password}")
    private String password;
    @Value("${user.sex}")
    private int sex;

    //定义bean对象
    @Bean
    //也可以通过注解的name修改bean名称
    //@Bean(name="user1")
    public SysUser user( SysRole sysRole) {
        SysUser user = new SysUser();
        user.setRealName(realName);
        user.setAccount(account);
        user.setPassword(password);
        user.setSex(sex);
        user.setSysRole(sysRole);
        //返回对象会被注册到Spring容器中
        return user;
    }
    //注册"管理员"角色bean对象

//    @Bean
//    @Conditional(ConditionOnPropertyEnable.OnEnableCondition.class)
//    @ConditionOnPropertyEnable(enableProperty = "admin.enable")
//    public SysRole adminSysRole() {
//        SysRole sysRole = new SysRole();
//        sysRole.setId(1L);
//        sysRole.setRoleName("管理员");
//        sysRole.setCode("ADMIN");
//        return sysRole;
//    }
//
//    @Bean
//    @Conditional(ConditionOnPropertyEnable.OnEnableCondition.class)
//    @ConditionOnPropertyEnable(enableProperty = "manager.enable")
//    public SysRole managerSysRole() {
//        SysRole sysRole = new SysRole();
//        sysRole.setId(2L);
//        sysRole.setRoleName("店长");
//        sysRole.setCode("MANAGER");
//        return sysRole;
//    }

//    @Bean
//    @Conditional(ConditionOnPropertyEnable.OnEnableCondition.class)
//    @ConditionOnPropertyEnable(enableProperty = "admin.enable")
//    public  SysRole adminSysRole() {
//        SysRole sysRole=new SysRole();
//        sysRole.setId(1l);
//        sysRole.setRoleName("管理员");
//        sysRole.setCode("ADMIN");
//        return sysRole;
//    }
//    @Bean
//    @Conditional(ConditionOnPropertyEnable.OnEnableCondition.class)
//    @ConditionOnPropertyEnable(enableProperty = "manager.enable")
//    public  SysRole managerSysRole() {
//        SysRole sysRole=new SysRole();
//        sysRole.setId(2l);
//        sysRole.setRoleName("店长");
//        sysRole.setCode("MANAGER");
//        return sysRole;
//    }

//    @Bean
//    @Conditional(ConditionOnPropertyEnable.OnEnableCondition.class)
//    @ConditionOnPropertyEnable(enableProperty  ="admin.enable")
//    public SysRole adminSysRole() {
//        SysRole sysRole = new SysRole();
//        sysRole.setId(1l);
//        sysRole.setRoleName("管理员");
//        sysRole.setCode("ADMIN");
//        return sysRole;
//    }

//    @Bean
//    @Conditional(ConditionOnPropertyEnable.OnEnableCondition.class)
//    @ConditionOnPropertyEnable(enableProperty  ="manager.enable")
//    public SysRole managerSysRole() {
//        SysRole sysRole = new SysRole();
//        sysRole.setId(2l);
//        sysRole.setRoleName("店长");
//        sysRole.setCode("MANAGER");
//        return sysRole;
//    }

//    @Bean
//    @Conditional(ConditionOnPropertyEnable.OnEnableCondition.class)
//    @ConditionOnPropertyEnable(enableProperty = "admin.enable")
//    public SysRole adminSysRole() {
//        SysRole sysRole = new SysRole();
//        sysRole.setId(1l);
//        sysRole.setRoleName("管理员");
//        sysRole.setCode("ADMIN");
//        return sysRole;
//    }
//    @Bean
//    @Conditional(ConditionOnPropertyEnable.OnEnableCondition.class)
//    @ConditionOnPropertyEnable(enableProperty = "manager.enable")
//
//    public SysRole managerSysRole() {
//        SysRole sysRole = new SysRole();
//        sysRole.setId(2l);
//        sysRole.setRoleName("店长");
//        sysRole.setCode("MANAGER");
//        return sysRole;
//    }

    @Bean
    @Conditional(ConditionOnPropertyEnable.OnEnableCondition.class)
    @ConditionOnPropertyEnable(enableProperty = "admin.enable")
    public SysRole adminSysRole(){
        SysRole sysRole=new SysRole();
        sysRole.setId(1l);
        sysRole.setRoleName("管理员");
        sysRole.setCode("ADMIN");
        return sysRole;
    }
    @Bean
    @Conditional(ConditionOnPropertyEnable.OnEnableCondition.class)
    @ConditionOnPropertyEnable(enableProperty = "manager.enable")
    public SysRole managerSysRole(){
        SysRole sysRole=new SysRole();
        sysRole.setId(2l);
        sysRole.setRoleName("店长");
        sysRole.setCode("MANAGER");
        return sysRole;
    }
}
